package org.focusj.scala.colls

object Coll {

    object TestScalaAction {
        def mul(factor: Double) = (x: Double) => factor * x //放回乐意个函数 Double => Double。相当于js中的val fn = function(d: Double) {return d * d}

        def main(args: Array[String]) {
            println("s" * 5)
        }

        def runInThread(t: => Unit) {
            new Thread {
                override def run() {
                    t
                }
            }.start()
        }
        //展示如何调用
        runInThread { println("1"); println(2) }

        def until(condition: Boolean)(proc: => Unit) {
            if (!condition)
                proc
            until(condition)(proc)
        }

        def t() {
            val a = Array("a", "b", "c")
            a.foldLeft("_")(_ + _) //1
            ("_" /: a)(_ + _) //2 ,1, 2是等价写法
        }

        def foldFn() = {
            val freq = scala.collection.mutable.Map[Char, Int]()
            for (c <- """Congragtulations""") freq(c) = freq.getOrElse(c, 0) + 1
        }

        def foldFn2() =
            (Map[Char, Int]() /: """Congragtulations""") {
                (m /*map element*/ , c /*右侧被展开的但愿*/ ) => m + (c -> (m.getOrElse(c, 0) + 1))
            }

    }
}